package com.mk.controller.user;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mk.entity.Illegal;
import com.mk.result.Result;
import com.mk.service.IIllegalService;
import com.mk.vo.IllegalVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 小程序违法处理业务
 */
@RestController("userIllegalController")
@RequestMapping("/user/illegal")
@RequiredArgsConstructor
public class IllegalController {

    private final IIllegalService illegalService;

    /**
     * 根据宠物id查询宠物的未处理罚款记录
     * @return
     */
    @CrossOrigin
    @GetMapping("/select/untreated")
    public Result<List<IllegalVO>> selectUntreated(Long petId) {
        List<Illegal> illegalList = illegalService.list(new LambdaQueryWrapper<Illegal>()
                .eq(Illegal::getPetId, petId)
                .eq(Illegal::getStatus, Illegal.UNTREATED));
        List<IllegalVO> list = new ArrayList<>();
        BeanUtil.copyProperties(illegalList, list);
        return Result.success(list);
    }

    /**
     * 根据宠物id查询宠物的已处理罚款记录
     * @return
     */
    @CrossOrigin
    @GetMapping("/select/treated")
    public Result<List<IllegalVO>> selectTreated(Long petId) {
        List<Illegal> illegalList = illegalService.list(new LambdaQueryWrapper<Illegal>()
                .eq(Illegal::getPetId, petId)
                .eq(Illegal::getStatus, Illegal.ALREADY_TREATED));
        List<IllegalVO> list = new ArrayList<>();
        BeanUtil.copyProperties(illegalList, list);
        return Result.success(list);
    }

    //TODO 复习微信支付，编写罚款缴纳的代码


}
